package joney.main;

import joney.main.action.AccountActions;
import joney.main.action.FileActions;

import org.eclipse.jface.action.AbstractAction;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IContributionItem;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.action.Separator;
import org.eclipse.ui.IWorkbenchActionConstants;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.actions.ActionFactory;
import org.eclipse.ui.actions.ContributionItemFactory;
import org.eclipse.ui.actions.ActionFactory.IWorkbenchAction;
import org.eclipse.ui.application.ActionBarAdvisor;
import org.eclipse.ui.application.IActionBarConfigurer;

/**
 * An action bar advisor is responsible for creating, adding, and disposing of
 * the actions added to a workbench window. Each window will be populated with
 * new actions.
 */
public class ApplicationActionBarAdvisor extends ActionBarAdvisor {

	private IWorkbenchAction exitAction, prefs;

	private AbstractAction save, saveAs, open, newAccount, deleteAccount, transfer, offset, clearAll, importFile;
	
	private IContributionItem perspectives;
	
	public ApplicationActionBarAdvisor(IActionBarConfigurer configurer) {
		super(configurer);
	}

	protected void makeActions(final IWorkbenchWindow window) {
		prefs = ActionFactory.PREFERENCES.create(window);
        register(prefs);

		exitAction = ActionFactory.QUIT.create(window);
		register(exitAction);
		
		importFile = new FileActions.Import(window);
		register(importFile);
		
		save = new FileActions.Save(window);
		//save.setAccelerator(SWT.MOD1 + 'S');
		register(save);
		
		saveAs = new FileActions.SaveAs(window);
		register(saveAs);
		
		open = new FileActions.Open(window);
		register(open);
		
		newAccount = new AccountActions.NewAccount(window);
		register(newAccount);
		
		deleteAccount = new AccountActions.DeleteAccount(window);
		register(deleteAccount);
		
		transfer = new AccountActions.TransferAmount(window);
		register(transfer);
		
		offset =  new AccountActions.OffsetAccount(window);
		register(offset);
		
		clearAll = new AccountActions.ClearAll(window);
		register(clearAll);
		
		perspectives = ContributionItemFactory.PERSPECTIVES_SHORTLIST.create(window);
		
	}

	protected void fillMenuBar(IMenuManager menuBar) {
		MenuManager fileMenu = new MenuManager("&File",
				IWorkbenchActionConstants.M_FILE);
		menuBar.add(fileMenu);
		
		fileMenu.add(open);
		
		fileMenu.add(save);
		fileMenu.add(saveAs);
		
		fileMenu.add(new Separator());
		
		fileMenu.add(importFile);
		
		fileMenu.add(new Separator());
		
		fileMenu.add(exitAction);
		
		MenuManager medit = new MenuManager("&Edit",
		"Edit");

		menuBar.add(medit);
		medit.add(prefs);
		
		
		MenuManager account = new MenuManager("&Account",
				"Account");
		menuBar.add(account);
		account.add(newAccount);
		account.add(deleteAccount);
		account.add(offset);
		account.add(clearAll);
		account.add(transfer);
		
		
		MenuManager window = new MenuManager("&Window",
		"Window");
		
		menuBar.add(window);
		window.add(perspectives);
		
		
		
		
		
		
	}

}
